//生成时间:2022-08-15 09:17
var emp={
    s_no:null,//工号
    Set_s_no:function(s_no){
        if(s_no.length<1 || s_no.length>20){
            return '工号的字数必须在1~20之间';
        }
        var reg=/^([A-Z]|[a-z]|\d)(\d{4,17}|(\d{4,17}[A-Z]\d{0,4}))|(^\d{18}$)|(^\d{17}(\d|X|x)$)$/;
        var patt=new RegExp(reg);
        if(!patt.test(s_no)){
            return '工号的格式不符合规定';
        }
        emp.s_no=s_no.replace(/\'/g,"&apos;");
    },
    s_name:null,//姓名
    Set_s_name:function(s_name){
        if(s_name.length<0 || s_name.length>90){
            return '姓名的字数必须在0~90之间';
        }
        emp.s_name=s_name.replace(/\'/g,"&apos;");
    },
    UseForm: function (elem) {
        for (var key in emp) {
            if (typeof emp[key] == "function") {
                continue;//过滤方法
            }
            if (elem.querySelector("#" + key) ==null) {
                continue;//过滤不存在表单组件
            }
            var val = "";
            if(['INPUT','SELECT','TEXTAREA'].indexOf(elem.querySelector("#"+key).nodeName)>-1){;
                val=elem.querySelector("#"+key).value;
            };
            if(['IMG'].indexOf(elem.querySelector("#"+key).nodeName)>-1){;
                val=elem.querySelector("#"+key).src;
            };
            var res = emp["Set_" + key](val);
            if (res) {
                return res;
            }
        }
        return null;
    },
    CreateFormdata: function () {
        var postData = new FormData();
        for (var key in emp) {
            if (typeof emp[key] == "function") {
                continue;//过滤方法
            }
            if (emp[key] == null) {
                  continue;
            }
            postData.append(key, emp[key]);
        }
        return postData;
    },
    CreateJson: function () {
        var json = {};
        for (var key in emp) {
            if (typeof emp[key] == "function") {
                continue;//过滤方法
            }
            if (emp[key] == null) {
                  continue;
            }
            json[key] = emp[key];
        }
        return json;
    }
}
